<?php

    set_time_limit(0);
    ob_implicit_flush();
	
	$address = 'localhost';
    $port    = 10001;
    $socket  = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
	
	if (FALSE == ($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
		die("Couldn't work with socket, error code is: " . socket_last_error() .",error message is: " . socket_strerror(socket_last_error()));
    }
	if (socket_connect($socket, $address, $port) == FALSE){
		die("Couldn't work with socket, error code is: " . socket_last_error() .",error message is: " . socket_strerror(socket_last_error()));
	}
	$msg = 'test1';
	socket_write($socket, $msg);
	$out = socket_read($socket, 1024);
    echo $out."<br>";
	
	$msg = 'test2';
	socket_write($socket, $msg);
	$out = socket_read($socket, 1024);
    echo $out."<br>";
	
	$msg = 'test3';
	socket_write($socket, $msg);
	$out = socket_read($socket, 1024);
    echo $out."<br>";
	
	$msg = 'close socket';
	socket_write($socket, $msg);
	$out = socket_read($socket, 1024);
    echo $out."<br>";
	
	socket_close($sock);
?>